﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XBoshiGFS.forms
{
    public partial class PriceMaintainForm : Form
    {
        public StationSet station { set; get; }
        XBoshiGFSModelContainer context = new XBoshiGFSModelContainer();
        List<FeeStandardSet> dataList = new List<FeeStandardSet>();


        


        public PriceMaintainForm()
        {
            InitializeComponent();
            var a = from p in context.FeeStandardSet select  p ;
            dataList = a.ToList();
            feeStandBindingSource.DataSource = a.ToList() ;
        }

        public PriceMaintainForm(StationSet station)
        {
            InitializeComponent();
            this.station = station;
            BindData();

        }

        public PriceMaintainForm(StationSet station,bool ReadOnly)
        {
            
            InitializeComponent();
            this.station = station;
            BindData();
            feeStandardGrid.ReadOnly = ReadOnly;
            btnSave.Visible = !ReadOnly; 



        }



        public void BindData() {
                var a = from p in context.FeeStandardSet select p;
                dataList = a.ToList();
                feeStandBindingSource.DataSource = dataList; 
        }
        
        private void feeStandardGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void PriceMaintainForm_Load(object sender, EventArgs e)
        {
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            context.SaveChanges();  
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FeeStandardSet newFee = new FeeStandardSet();
            context.AddToFeeStandardSet(newFee);  
            newFee.Id = Guid.NewGuid().ToString();
            newFee.StationSet = (from p in context.StationSet where p.Id==station.Id select  p ).FirstOrDefault ();
            dataList.Add(newFee);
            feeStandBindingSource.DataSource = dataList;



        }

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

 
    }
}
